faApp.controller('BehaviorCtrl', ['$cookieStore','$scope','$routeParams','beService','$location', '$controller', function($cookieStore,$scope,$routeParams,beService, $location, $controller) {
	$controller('BaseListCtrl', {
		$scope: $scope
	});
	$scope.userList = [];
	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1
	}
	//设置默认的查询参数
	if($routeParams.startDate){
		$scope.searchMap['startDate'] = $routeParams.startDate;
	}
	if($routeParams.endDate){
		$scope.searchMap['endDate'] = $routeParams.endDate;
	}
	if($routeParams.flagLogin){
		$scope.searchMap['flagLogin'] = $routeParams.flagLogin;
	}
	if($routeParams.ip){
		$scope.searchMap['ip'] = $routeParams.ip;
	}
	// if($routeParams.loginName){
	// 	$scope.searchMap['loginName'] = $routeParams.loginName;
	// }
	if($routeParams.isSearch){
		$scope.search()
	}
	
	console.log($scope.config);
	$scope.$watch('config', function(cfg) {
		if ($scope.watchIsChange()) {
			beService.getDataList($scope.config).then(function(json){

		        $scope.userList = json.list || [];
		        $scope.pager = json.pager;
		        $scope.searchMap['startDate'] = $scope.searchMap['startDate'] ? $scope.searchMap['startDate'] : json.nowDate;
		        $scope.searchMap['endDate'] = $scope.searchMap['endDate'] ? $scope.searchMap['endDate'] : json.nowDate;

			})
		}
	}, true);

	// $scope.searchMap.flagLogin = 2; //默认未登录
	$scope.search = function() {
		angular.forEach($scope.searchMap, function(o, i) {
			$scope.config[i] = (undefined == $scope.searchMap[i] ? "" : $scope.searchMap[i]);
		});

	};
	var query = [];
	$scope.toView = function(cfg) {
		var name = $scope.config.loginName;
		$scope.config.loginName = name ? name : cfg;
		angular.forEach($scope.config,function(o,i){
			query.push(i + "=" + $scope.config[i]);
		}) 
		var url = 'behavior/view?'+query.join("&");
		// alert(url);
		$location.url(url);
	}

}]);
faApp.controller('BehaviorViewCtrl',['$scope','beService','$routeParams','$location','$controller',function($scope,beService,$routeParams, $location, $controller) {
	$controller('BaseListCtrl', {
		$scope: $scope
	});	
	console.log('BehaviorViewCtrl');
	$scope.arr = $routeParams;
	$scope.staticHost=App.staticHost;
	var query = [];
	angular.forEach($scope.arr,function(o,i){
		query.push(i + "=" + $scope.arr[i])
	})
	$scope.url = '#/behavior/list?isSearch=1&'+query.join("&");
	$scope.behavior = {
		remarkInfo : ''
	};
	
	beService.getDateInfo($scope.arr).then(function(json){
		
		$scope.btnList = json.info;
		// var result = btnTypeNoRepeat(json.info);//去掉重复点击的type
	}) 
	
	$scope.addRemark = function() {
		if( $scope.behavior.remarkInfo.length > 250 ) {
			alert("输入文字过长，请数日250个字之内");
			return
		}else if( $scope.behavior.remarkInfo.length == 0 ){
			alert("输入文字内容");
			return
		}
		beService.addRemark({loginName : $scope.arr.loginName, remark : $scope.behavior.remarkInfo}).then(function(json){
		  if (!json.statusCode){
			beService.faUserVisit($scope.arr.loginName).then(function(json){
			  $scope.visitList = json.list;
			});
			$scope.behavior.remarkInfo = "";
		  }else{
			alert("出错了:" + json.statusCode);
		  }  
		});
	} 
	
	$scope.visitList = [];
	beService.faUserVisit($scope.arr.loginName).then(function(json){
		$scope.visitList = json.list;
	});
	
}]);
// //去除重复的点击
// function btnTypeNoRepeat(arr) {

// 	var result = [],
// 		isRepeated;
// 	for (var i = 0 ; i < arr.length; i++) {
// 		isRepeated = false;
// 		for (var j = 0 ; j < result.length; j++) {
// 			if (arr[i].type == result[j].type) {
// 				isRepeated = true;
// 				break;
// 			}
// 		}
// 		if (!isRepeated) {
// 			result.push(arr[i]);
// 		}
// 	}
// 	return result;
// }